﻿using UnityEngine;
using System.Collections;

public class MyPlayerPrefabs {

		/*    set      */
	public static void setInt(string key, int value){
		PlayerPrefs.SetInt (key, value);
	}

	public static void setString(string key, string value){
		PlayerPrefs.SetString (key, value);
	}

	public static void setFloat(string key, float value){
		PlayerPrefs.SetFloat (key, value);
	}

	public static void setIntArr(string key, int[] value){
		int size = value.Length;
		for(int i = 0;i < size;i++){
			PlayerPrefs.SetInt (key + i, value[i]);
		}
	}

	public static void setStringArr(string key, string[] value){
		int size = value.Length;
		for(int i = 0;i < size;i++){
			PlayerPrefs.SetString (key + i, value[i]);
		}
	}

	public static void setFloatArr(string key, float[] value){
		int size = value.Length;
		for(int i = 0;i < size;i++){
			PlayerPrefs.SetFloat (key + i, value[i]);
		}
	}		

		/*    get      */
	public static int getInt(string key){
		return PlayerPrefs.GetInt (key);
	}

	public static int getInt(string key, int defaultVal){
		return PlayerPrefs.GetInt (key, defaultVal);
	}

	public static string getString(string key){
		return PlayerPrefs.GetString (key);
	}

	public static string getString(string key, string defaultVal){
		return PlayerPrefs.GetString (key, defaultVal);
	}

	public static float getFloat(string key){
		return PlayerPrefs.GetFloat (key);
	}

	public static float getFloat(string key, float defaultVal){
		return PlayerPrefs.GetFloat (key, defaultVal);
	}

	public static ArrayList getIntArr(string key){
		ArrayList list = new ArrayList ();
		int i = 0;
		while(true){
			if (!PlayerPrefs.HasKey(key + i))
				break;
			
			int val = PlayerPrefs.GetInt (key + i);
			list.Add (val);
			i++;
		}
		return list;
	}

	public static ArrayList getStringArr(string key){
		ArrayList list = new ArrayList ();
		int i = 0;
		while(true){
			if (!PlayerPrefs.HasKey (key + i))
				break;
			
			string val = PlayerPrefs.GetString (key + i);
			list.Add (val);
			i++;
		}
		return list;
	}

	public static ArrayList getFloatArr(string key){
		ArrayList list = new ArrayList ();
		int i = 0;
		while(true){
			if (!PlayerPrefs.HasKey(key + i))
				break;

			float val = PlayerPrefs.GetFloat (key + i);
			list.Add (val);
			i++;
		}
		return list;
	}

	/*    delete      */
	public static void deleteKey(string key){
		int i = 0;
		while(PlayerPrefs.HasKey(key + i)){
			PlayerPrefs.DeleteKey (key);
		}
	}
	public static bool HasKey(string key){
		return PlayerPrefs.HasKey (key);
	}

//	public static void deleteIntArr(string key){
//		int i = 0;
//		while(true){
//			if (!PlayerPrefs.HasKey (key + i))
//				break;			
//			
//			PlayerPrefs.DeleteKey (key + i);
//			i++;
//		}
//	}
//
//	public static void deleteStringArr(string key){
//		int i = 0;
//		while(true){
//			if (!PlayerPrefs.HasKey (key + i))
//				break;	
//			
//			PlayerPrefs.DeleteKey (key + i);
//			i++;
//		}
//	}
//
//	public static void deleteFloatArr(string key){
//		int i = 0;
//		while(true){
//			if (!PlayerPrefs.HasKey (key + i))
//				break;
//			
//			PlayerPrefs.DeleteKey (key + i);
//			i++;
//		}
//	}


	void Awake(){
		
	}
}
